import { Controller, Get, Param } from '@nestjs/common';
import { PrismaService } from 'src/prisma/prisma.service';

@Controller('line')
export class LineController {
    constructor(
        private readonly prismaService: PrismaService
    ) { }

    @Get(":id/set/:value")
    async set(
        @Param("id") hash_id: string,
        @Param("value") value: string
    ) {
        if (await this.prismaService.line.findFirst({ where: { hash_id } })) {
            return await this.prismaService.line.update({
                where: {
                    hash_id
                },
                data: {
                    value
                }
            })
        }
        return await this.prismaService.line.create({
            data: {
                hash_id,
                value
            }
        })
    }

    @Get(":id/get")
    async get(
        @Param("id") hash_id: string
    ) {
        const result = await this.prismaService.line.findFirst({
            where: {
                hash_id
            }
        })
        if (!result) return {};
        return result;
    }
}
